# -*- coding: utf-8 -*-


import time
import threading
import queue  # python3


# import Queue  # python2


global_queue = queue.Queue()
global_count = 1


class Producer(threading.Thread):
    """消费者"""

    def run(self):
        global global_queue
        global global_count
        while True:
            if global_queue.qsize() <= 6:
                for x in range(3):
                    # 生产
                    global_queue.put(global_count)
                    print('%s Producer:%d' % (self.name, global_count))
                    global_count += 1
                    pass
                pass
            pass
            time.sleep(1)
        pass

    pass


class Customer(threading.Thread):
    """生产者"""

    def run(self):
        global global_queue
        while True:
            if global_queue.qsize() >= 6:
                for y in range(2):
                    # 消费
                    print('%s Customer:%d' % (self.name, global_queue.get()))
                    pass
                pass
            pass
            time.sleep(1)
        pass

    pass


def producer_customer():
    """生产者消费者问题"""
    global global_queue
    global global_count

    for i in range(6):
        global_queue.put(global_count)
        print('%s Initialize:%d' % (threading.currentThread().getName(), global_count))
        global_count += 1
        pass

    for i in range(2):
        producer = Producer()
        producer.start()
        pass

    for i in range(3):
        customer = Customer()
        customer.start()
        pass

if __name__ == '__main__':



    pass
